<template>
    <div class="number-statistics">
        <div :class="['item', props.isShowBack ? 'back' : '']" :style="{ width: width }" v-for="(item, index) in props.data" :key="index">
            <div class="top">
                <div class="count">{{ item.count }}</div>
                <div class="unit">{{ item.unit }}</div>
            </div>
            <div class="name">{{ item.name }}</div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref, watch } from 'vue'

const props = defineProps({
    isShowBack: {
        type: Boolean,
        default: false
    },
    rows: {
        type: Number,
        default: 3
    },
    height: {
        type: Number,
        default: 150
    },
    data: {
        default: () => [
            {
                count: 2732,
                unit: '人',
                name: '当前总人数'
            },
            {
                count: 2800,
                unit: '人',
                name: '总进入人数'
            },
            {
                count: 2780,
                unit: '人',
                name: '总离开人数'
            }
        ]
    }
})

const width = ref('33%')

watch(
    () => props.rows,
    newVal => {
        if (newVal == 2) {
            width.value = '45%'
        } else if (newVal == 3) {
            width.value = '30%'
        } else if (newVal == 4) {
            width.value = '20%'
        }
    },
    {
        immediate: true
    }
)
</script>

<style scoped lang="scss">
.number-statistics {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 10px 20px;
    margin-bottom: 5px;
    color: #fff;
    .item {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        margin-bottom: 20px;
        margin-right: 10px;
        height: v-bind('props.height');
        .top {
            display: flex;
            align-items: flex-end;
            margin-bottom: 10px;
            .count {
                font-size: 28px;
                margin-right: 10px;
                font-family: SJyunhei;
            }
            .unit {
                font-size: 14px;
                opacity: 0.5;
            }
        }
        .name {
            font-family: OPPOSans;
            font-size: 16px;
            letter-spacing: 2px;
            color: #89cbff;
        }
    }
    .back {
        background: url('@/assets/images/基础/infobox_Bg4c.png') no-repeat;
        background-size: 100% 100%;
    }
}
</style>
